<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="bean.User" %>
<%@ page import="bean.News" %>
<%@ page import="java.util.List" %>
<%@ page import="bean.NewsofUser" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>时讯界新闻发布系统</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/normalize/8.0.1/normalize.min.css" rel="stylesheet">
    <link href="https://unpkg.com/@wangeditor/editor@latest/dist/css/style.css" rel="stylesheet">
    <style>
        body {
            background-color: #eaf6f6;
        }
        .container-fluid {
            display: flex;
            height: 100vh;
            padding: 0;
        }
        .sidebar {

            background-color: #333;
            /*background-color: #2aabd2;*/
            color: white;
            padding-top: 20px;
            flex: 0 0 200px; /* fixed width for sidebar */
            display: flex;
            flex-direction: column;
            align-items: center;
            height: 100vh;
        }
        .sidebar a {
            color: white;
            display: block;
            padding: 10px 15px;
            text-decoration: none;
            width: 100%;
            text-align: center;
        }
        .sidebar a:hover, .sidebar .active {
            /*background-color: #2aabd2;*/
            background-color: #575757;
            text-decoration: none;
        }
        .main-content {
            background-color: #eaf6f6;
            flex-grow: 1;
            padding: 30px;
            display: flex;
            flex-direction: column;
        }
        .user-info {
            text-align: center;
            padding: 20px 0;
        }
        .user-info img {
            width: 60px;
            border-radius: 50%;
        }
        .user-info p {
            margin: 10px 0 0;
        }
        .editor-container {
            flex-grow: 1;
            display: flex;
            flex-direction: column;
        }
        #editor-text-area {
            flex-grow: 1;
            height: auto;
        }
        .table-container {
            margin-bottom: 20px;
        }
        .center-container {
            display: flex;
            justify-content: center;
            margin-top: 20px;
        }
        .icon {
            width: 20px;
            height: 20px;
            vertical-align: middle; /* 调整 SVG 和文字的垂直对齐 */
        }
        .nav-link {
            display: flex;
            align-items: center; /* 垂直居中对齐 */
        }
        .nav-link a {
            text-decoration: none;
            color: inherit;
            margin-left: 5px; /* 图标和文字之间的间距 */
        }
    </style>
</head>
<body>
<% User user = (User) request.getSession().getAttribute("user");

    Integer start = (Integer) request.getSession().getAttribute("start");
%>

<div class="container-fluid">

    <div class="col-md-10 main-content">
        <div class="mb-3">
            <button class="btn btn-primary" onclick="redirectToPage()">发布新闻</button>
            <form class="d-inline-block w-auto ml-2" action="../newsMan.do" method="post">
                <input type="text" class="form-control d-inline-block w-auto ml-2" name="select" placeholder="查询新闻">
                <input class="btn btn-secondary ml-2" type="submit" value="查询" name="submit"/>
            </form>
        </div>
        <div class="table-container" style="width: 1230px;">
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>封面图片</th>
                    <th>新闻标题</th>
                    <th>发布人</th>
                    <th>发布时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:if test="${start == 0}">
                    <tr>
                        <td>1(样例)</td>
                        <td><img src="../resources/newsimg.png" alt="新闻封面" width="20" height="20"></td>
                        <td><a href="#">新闻标题1</a></td>
                        <td>发布人</td>
                        <td>2023-01-01</td>
                        <td>
                            <a class="btn btn-warning btn-sm" href="#" >修改</a> &nbsp;
                            <a class="btn btn-danger btn-sm" href="#" onclick="return confirm('是否删除？')">删除</a>
                        </td>
                    </tr>
                </c:if>
                <c:forEach var="u" items="${newsselectlist}">
                    <tr>
                        <td>${u.newsid }</td>
                        <td>
                            <img src="${ u.newsimg}" alt="新闻封面" width="50" height="50">
                            <!-- 输出调试信息 -->
<%--                            <c:out value="${ u.headimg}" />--%>
                        </td>
                        <td><a href="/press_release_system_war_exploded/newsview.do?newsid=${u.newsid }">${u.newstitle }</a></td>
                        <td>${u.username }</td>
                        <td>${u.pubtime }</td>
                        <td>
                            <c:if test="${!isUserAdmin}">

                                <c:if test="${u.userid==user.getId()}">
                                    <a class="btn btn-warning btn-sm" href="../newsMan.do?updateid=${u.newsid }" >修改</a> &nbsp;
                                    <a class="btn btn-danger btn-sm" href="../newsMan.do?deleteid=${u.newsid }" onclick="return confirm('是否删除？')">删除</a>
                                </c:if>
                                <c:if test="${u.userid!=user.getId()}">
                                <a class="btn btn-warning btn-sm" href="#" onclick="return confirm('您没有权限修改！')">修改</a> &nbsp;
                                <a class="btn btn-danger btn-sm" href="#" onclick="return confirm('您没有权限删除！')">删除</a>
<%--                                </c:if>--%>
                                </c:if>
                            </c:if>
                            <c:if test="${isUserAdmin}">
                                <a class="btn btn-warning btn-sm" href="../newsMan.do?updateid=${u.newsid }" >修改</a> &nbsp;
                                <a class="btn btn-danger btn-sm" href="../newsMan.do?deleteid=${u.newsid }" onclick="return confirm('是否删除？')">删除</a>
                            </c:if>

                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
            <div class="center-container">
                <span class="center-text">${pageStr}</span>
            </div>
        </div>
    </div>
</div>

<script>
    function redirectToPage() {
        window.location.href = "publish.jsp";
    }
</script>
</body>
</html>
